package com.miracle9.game.service;

import com.miracle9.game.bean.GameStatus;
import com.miracle9.game.bean.GameTypeSession;
import com.miracle9.game.dao.PromoterServiceDao1;
import com.miracle9.game.dao.SystemConfigServiceDao;
import com.miracle9.game.dao.UserServiceDao;
import com.miracle9.game.entity.*;
import com.miracle9.game.server.message.AmfMessageSend;
import com.miracle9.game.server.message.MessageSend;
import com.miracle9.game.server.message.StorageMethodEntity;
import com.miracle9.game.server.message.WaterSocketHandler;
import com.miracle9.game.util.GameParameterAssist;
import com.miracle9.game.util.MyUtil;
import com.miracle9.game.util.SessionUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@Service("systemConfigService")
public class SystemConfigService extends BaseService {

    @Autowired
    private SystemConfigServiceDao systemConfigServiceDao;
    @Autowired
    private com.miracle9.game.dao.AdminServiceDao adminServiceDao;
    @Autowired
    private com.miracle9.game.dao.AdminLogServiceDao adminLogServiceDao;
    @Autowired
    private UserServiceDao userServiceDao;
    @Autowired
    private com.miracle9.game.dao.BusineServiceDao busineServiceDao;
    @Autowired
    private com.miracle9.game.dao.BusineInfoServiceDao busineInfoServiceDao;
    @Autowired
    private BusineService a;
    @Autowired
    private PromoterServiceDao1 promoterServiceDao1;
    @Autowired
    private UserRegistLogService userRegistLogService;

    public SystemConfig getSystemConfig() {
        return this.systemConfigServiceDao.getSystemConfig();
    }

    public SystemConfig getSystemConfig(IoSession session) {
        return getSystemConfig();
    }

    public Map<String, Object> updateConfig(SystemConfig config, IoSession session) {
        Map result = new HashMap();
        StringBuilder content = new StringBuilder("修改系统设置");
        StringBuilder contentEn = new StringBuilder("Change system setting:");
        SystemConfig old = this.systemConfigServiceDao.getSystemConfig();
        if (old.getUserCheck() != config.getUserCheck()) {
            if (config.getUserCheck() == 0) {
                content.append("，关闭用户检查");
                contentEn.append("Close user inspection,");
            } else {
                content.append("，开启用户检查");
                contentEn.append("Open user inspection,");
            }
        }
        if (old.getPayCheckMoney() != config.getPayCheckMoney()) {
            content.append("，修改充值检测额度为" + config.getPayCheckMoney());
            contentEn.append("Change limit of recharge to " + config.getPayCheckMoney() + ",");
        }
        if (old.getExpiryCheckMoney() != config.getExpiryCheckMoney()) {
            content.append("，修改兑换检测额度为" + config.getExpiryCheckMoney());
            contentEn.append("Change limit of exchange to " + config.getExpiryCheckMoney() + ",");
        }
        if (old.getAuthorize() != config.getAuthorize()) {
            if (config.getAuthorize() == 0) {
                content.append("，关闭授权");
                contentEn.append("Close authorizate function,");
            } else {
                content.append("，开启授权");
                contentEn.append("Open authorizate function,");
            }
        }
        if (old.getSumPayMoney() != config.getSumPayMoney()) {
            if (config.getSumPayMoney() == -1) {
                content.append("，修改日充值授权金额为不设上限");
                contentEn.append("Change daily recharge amount of authorization to unlimited,");
            } else {
                content.append("，修改日充值授权金额为" + config.getSumPayMoney());
                contentEn.append("Change daily recharge amount of authorization to " + config.getSumPayMoney() + ",");
            }
        }
        if (old.getSumExpiryMoney() != config.getSumExpiryMoney()) {
            if (config.getSumExpiryMoney() == -1) {
                content.append("，修改日兑换授权金额为不设上限");
                contentEn.append("Change daily exchange amount of authorization to unlimited,");
            } else {
                content.append("，修改日兑换授权金额为" + config.getSumExpiryMoney());
                contentEn.append("Change daily exchange amount of authorization to " + config.getSumExpiryMoney() + ",");
            }
        }
        if (old.getUserSumMoney() != config.getUserSumMoney()) {
            if (config.getUserSumMoney() == -1) {
                content.append("，修改单个会员日兑奖授权金额为不设上限");
                contentEn.append("Change single member daily exchange amount of authorization to " + config.getUserSumMoney() + ",");
            } else {
                content.append("，修改单个会员日兑奖授权金额为" + config.getUserSumMoney());
                contentEn.append("Change single member daily exchange amount of authorization to unlimited,");
            }
        }
        if (old.getPromoterSumMoney() != config.getPromoterSumMoney()) {
            if (config.getPromoterSumMoney() == -1) {
                content.append("，修改单个推广员日兑奖授权金额为不设上限");
                contentEn.append("Change single extension daily exchange amount of authorization to unlimited,");
            } else {
                content.append("，修改单个推广员日兑奖授权金额为" + config.getPromoterSumMoney());
                contentEn.append("Change single extension daily exchange amount of authorization to " + config.getPromoterSumMoney() + ",");
            }
        }
        if (old.getMoneyOverrun() != config.getMoneyOverrun()) {
            for (IoSession s : WaterSocketHandler.F) {
                AmfMessageSend.processStorageInfo(new StorageMethodEntity(s, "manageService/systemOverflow", new Object[]{Integer.valueOf(config.getMoneyOverrun())}));
            }
            if (config.getMoneyOverrun() == -1) {
                content.append("，修改爆机金额为不设上限");
                contentEn.append("Change max value of coins has to unlimited,");

                List<User> overflowUsers = this.userServiceDao.q_CreateSqlList("from User where overflow=1 and promoterId=0", new Object[0]);
                this.userServiceDao.q_CreateSql("update User set overflow=0 where overflow=1 and promoterId=0", new Object[0]).executeUpdate();
                for (User u1 : overflowUsers) {
                    if (GameParameterAssist.ba.containsKey(Integer.valueOf(u1.getId()))) {
                        MessageSend.q.notifyAllOperating(new StorageMethodEntity((IoSession) GameParameterAssist.ba.get(Integer.valueOf(u1.getId())), "unOverflow", new Object[0]));
                    }
                }
            } else {
                content.append("，修改爆机金额为" + config.getMoneyOverrun());
                contentEn.append("Change max value of coins has to " + config.getMoneyOverrun() + ",");
                List<User> users = this.userServiceDao.q_CreateSqlList("from User where promoterId=0", new Object[0]);
                for (User u1 : users) {
                    int sumGameGold = u1.getGameGold();
                    if (sumGameGold * config.getPayScale() >= config.getMoneyOverrun() * 100) {
                        if (u1.getOverflow() == 0) {
                            this.userServiceDao.updateOverflow(u1.getId(), 1);
                            pubOverflowNotice(u1.getId());
                        }
                    } else if (u1.getOverflow() == 1) {
                        this.userServiceDao.updateOverflow(u1.getId(), 0);
                        if (GameParameterAssist.ba.containsKey(Integer.valueOf(u1.getId()))) {
                            MessageSend.q.notifyAllOperating(new StorageMethodEntity((IoSession) GameParameterAssist.ba.get(Integer.valueOf(u1.getId())), "unOverflow", new Object[0]));
                        }
                    }
                }
            }
        }
        if (old.getNotActive() != config.getNotActive()) {
            if (config.getNotActive() == -1) {
                content.append("，修改自动冻结为不设上限");
                contentEn.append("Change the amount of automatic freezing to unlimited,");
            } else {
                content.append("，修改自动冻结为" + config.getNotActive());
                contentEn.append("Change the amount of automatic freezing to " + config.getNotActive() + ",");
            }
        }
        if (old.getChat() != config.getChat()) {
            if (config.getChat() == 0) {
                content.append("，关闭聊天");
                contentEn.append("Turn off the chat function,");
            } else {
                content.append("，开启聊天");
                contentEn.append("Turn on the chat function,");
            }
            for (Set<IoSession> sessions : SessionUtils.getAllSession()) {
                for (IoSession s : sessions) {
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(s, "manageService/gameShutup", new Object[]{config.getChat() == 0}));
                }
            }
        }
        if (old.getRegistVerify() != config.getRegistVerify()) {
            if (config.getRegistVerify() == 0) {
                content.append("，关闭会员注册验证");
                contentEn.append("Turn off the regist verify function");
            } else {
                content.append("，开启会员注册验证");
                contentEn.append("Turn on the regist verify function");
            }
            this.userRegistLogService.cleanRegistApply();
            Map userRegistCountMap = this.userRegistLogService.userRegistCountMap();
            for (IoSession as : GameParameterAssist.be.values()) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(as, "userRegistCount", new Object[]{userRegistCountMap}));
            }
        }
        if (!old.getUpdateAddress().equals(config.getUpdateAddress())) {
            content.append("，修改游戏更新地址为：" + config.getUpdateAddress());
            contentEn.append("，Modify the game update address to：" + config.getUpdateAddress());
        }
        this.systemConfigServiceDao.updateSystemConfigAll(config);
        result.put("success", Boolean.TRUE);
        result.put("message", "");
        for (Map.Entry<Integer, IoSession> entry : GameParameterAssist.be.entrySet()) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(entry.getValue(), "syncConfig", new Object[]{config}));
        }
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog();
        adminLog.setAdmin(admin.getUsername());
        adminLog.setAuthority(admin.getType());
        adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        adminLog.setType(2);
        adminLog.setContent(content.toString());
        adminLog.setContentEn(contentEn.toString());
        this.adminLogServiceDao.addAdminLog(adminLog);
        return result;
    }

    private void pubOverflowNotice(int userId) {
        if (GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
            MessageSend.q.notifyAllOperating(new StorageMethodEntity(GameParameterAssist.ba.get(userId), "overflow", new Object[0]));
        }
        for (GameTypeSession gameTypeSession : SessionUtils.getSessionByUserId(userId)) {
            for (IoSession session : gameTypeSession.getSessionSet()) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(session, "manageService/overflow", new Object[]{userId}));
            }
        }
    }

    public Map<String, Object> updateSales(String payScaleStr, String promoterPayScaleStr, int switchType, int interactPassword, int expiry, IoSession session) {
        Map result = new HashMap();

        int payScale = (int) MyUtil.doubleMultiplyCalculation(Double.valueOf(payScaleStr).doubleValue(), 100.0D);

        int promoterPayScale = (int) MyUtil.doubleMultiplyCalculation(Double.valueOf(promoterPayScaleStr).doubleValue(), 100.0D);
        if ((payScale <= 0) || ((GameParameterAssist.bH) && (promoterPayScale <= 0))) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "payScaleThanZero"));
            return result;
        }
        SystemConfig sc = this.systemConfigServiceDao.getSystemConfig();
        StringBuilder content = new StringBuilder("修改销售设置");
        StringBuilder contentEn = new StringBuilder("Change sales setting:");
        if (sc.getSwitchType() != switchType) {
            Busine busine = this.busineServiceDao.getAndSave();
            if ((switchType == -1) && (busine != null) && (busine.getStatus() != 2)) {
                this.a.stopBusine(busine);

                this.busineInfoServiceDao.updateEndTime(MyUtil.dateFormatYMD_HMS_Sting(new Date()), busine.getId(), busine.getCurrentShiftType());
            }
        }
        if (sc.getPromoterPayScale() != promoterPayScale) {
            content.append("，设置直属推广员充值比例为" + promoterPayScaleStr);
            contentEn.append("Change recharge ratio of direct extensions to " + promoterPayScaleStr + ",");

            List<Promoter> promoters = this.promoterServiceDao1.q_CreateSqlList("from Promoter where parentId=0", new Object[0]);
            for (Promoter p : promoters) {
                IoSession s = (IoSession) GameParameterAssist.bx.get(Integer.valueOf(p.getId()));
                if (s != null) {
                    PromoterAppService.syncPromoterPayScale(promoterPayScale, s);
                }
            }
        }
        User u;
        if (sc.getPayScale() != payScale) {
            content.append("，设置所有会员充值比例为" + payScaleStr);
            contentEn.append("Change recharge ratio of all members to " + payScaleStr + ",");
            if (sc.getMoneyOverrun() != -1) {
                List<User> overUser = this.userServiceDao.q_CreateSqlList("from User", new Object[0]);
                Iterator localIterator;
                for (localIterator = overUser.iterator(); localIterator.hasNext(); ) {
                    u = (User) localIterator.next();

                    int overrunGold = 0;
                    if (u.getPromoterId() == 0) {
                        overrunGold = sc.getMoneyOverrun() * 100 / payScale;
                    } else {
                        Promoter promoter = (Promoter) this.promoterServiceDao1.getById(Integer.valueOf(u.getPromoterId()));
                        if (promoter != null) {
                            overrunGold = promoter.getChildrenUserOver() * 100 / payScale;
                        }
                    }
                    int sumGameGold = u.getGameGold();
                    if ((u.getOverflow() == 0) && (sumGameGold >= overrunGold)) {
                        this.userServiceDao.updateOverflow(u.getId(), 1);
                        pubOverflowNotice(u.getId());
                    } else if ((u.getOverflow() == 1) && (sumGameGold < overrunGold)) {
                        this.userServiceDao.updateOverflow(u.getId(), 0);
                        if (GameParameterAssist.ba.containsKey(Integer.valueOf(u.getId()))) {
                            MessageSend.q.notifyAllOperating(new StorageMethodEntity((IoSession) GameParameterAssist.ba.get(Integer.valueOf(u.getId())), "unOverflow", new Object[0]));
                        }
                    }
                }
            }
            for (IoSession s : GameParameterAssist.bx.values()) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(s, "syncUserPayScale", new Object[]{Integer.valueOf(payScale)}));
            }
        }
        sc.getInteractPassword();
        if (expiry != sc.getExpiry()) {
            if (expiry == -1) {
                content.append("，关闭远程充值兑奖申请");
                contentEn.append("Close the remote application of recharge and exchange");
            } else if (sc.getExpiry() == -1) {
                content.append("，开启远程充值兑奖申请");
                contentEn.append("Open the remote application of recharge and exchange");
            } else {
                content.append("，修改申请有效时限为" + expiry);
                contentEn.append("Change effective time of application to " + expiry);
            }
        }
        for (Map.Entry entry : GameParameterAssist.ba.entrySet()) {
            Object chargeMap = new HashMap();
            ((Map) chargeMap).put("status", Integer.valueOf(expiry == -1 ? 1 : 0));
            ((Map) chargeMap).put("poportion", Integer.valueOf(payScale));
            MessageSend.q.notifyAllOperating(new StorageMethodEntity((IoSession) entry.getValue(), "chargeOpen", new Object[]{chargeMap}));
        }
        this.systemConfigServiceDao.updateSystemConfigInfo_5(payScale, promoterPayScale, switchType, interactPassword, expiry);
        result.put("success", Boolean.valueOf(true));
        result.put("payScale", Integer.valueOf(payScale));
        result.put("promoterPayScale", Integer.valueOf(promoterPayScale));
        result.put("message", "");
        sc = this.systemConfigServiceDao.getSystemConfig();
        for (Map.Entry entry : GameParameterAssist.be.entrySet()) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity((IoSession) entry.getValue(), "syncConfig", new Object[]{sc}));
        }
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog(admin.getUsername(), content.toString(), 2, admin.getType(), contentEn.toString());
        this.adminLogServiceDao.addAdminLog(adminLog);
        return result;
    }

    public void resetTempConfig() {
        this.systemConfigServiceDao.resetTempConfig();
    }

    public Map<String, Object> updateGameStatus(GameStatus gs, IoSession session) {
        Map result = new HashMap();
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        if ((config.getOperationStatus() == 0) && (gs.statusIndex == 0) && (GameParameterAssist.bt)) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "setError"));
            return result;
        }
        String content = "设置游戏立即进入“运营”状态";
        String contentEn = "Set up the game into operating state immediately";
        if (gs.statusIndex == 2) {
            config.setWeihuTime(gs.time);
            config.setContent(gs.content);
            config.setGameStatus(0);
            this.systemConfigServiceDao.updateWeihuStatus(config);
            Calendar c = Calendar.getInstance();
            int h = c.get(11);
            if (h > gs.time) {
                c.add(5, 1);
            }
            content = "设置游戏定时进入“维护”状态，时间是 " + MyUtil.dateFormatYMD_Sting(c.getTime()) + " " + gs.time + "点";
            SimpleDateFormat sdf = new SimpleDateFormat("yy,MM,dd");
            contentEn = "Set up the game into maintenance state at " + sdf.format(new Date()) + "," + gs.time;
        } else {
            config.setGameStatus(gs.statusIndex);
            config.setWeihuTime(-1);
            config.setContent("");
            this.systemConfigServiceDao.updateWeihuStatus(config);
            if (gs.statusIndex == 1) {
                content = "设置游戏立即进入“维护”状态";
                contentEn = "Set up the game into maintenance state immediately";
                pubNotice();
            }
        }
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog(admin.getUsername(), content, 1, admin.getType(), contentEn);
        this.adminLogServiceDao.addAdminLog(adminLog);

        gs.cooperateMode = config.getOperationStatus();
        gs.cooperateStartDate = "——————";
        gs.cooperateEndDate = "——————";
        SimpleDateFormat sdf;
        if (config.getOperationStatus() == 1) {
            gs.cooperateStartDate = config.getOperationDate();
            Calendar c = Calendar.getInstance();
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            c.setTimeInMillis(config.getOperationStopDate());
            gs.cooperateEndDate = sdf.format(c.getTime());
        }
        for (Map.Entry entry : GameParameterAssist.be.entrySet()) {
            if (!session.equals(entry.getValue())) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity((IoSession) entry.getValue(), "syncGameStatus", new Object[]{gs}));
            }
        }
        result.put("success", Boolean.TRUE);
        result.put("message", "success");
        return result;
    }

    public void pubNotice() {
        for (Integer uid : GameParameterAssist.ba.keySet()) {
            Map<String, Object> m = new HashMap<>();
            m.put("type", 1);
            MessageSend.q.notifyAllOperating(new StorageMethodEntity(GameParameterAssist.ba.get(uid), "quitToLogin", new Object[]{m}));
        }
        GameParameterAssist.ba = new ConcurrentHashMap<>();
        for (Set<IoSession> ioSessions : SessionUtils.getAllSession()) {
            for (IoSession s : ioSessions) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity(s, "manageService/quitToLogin", new Object[]{-1, 1}));
            }
        }

        GameParameterAssist.bi = new ConcurrentHashMap<>();
        GameParameterAssist.bh = new ConcurrentHashMap<>();
        GameParameterAssist.bj = new ConcurrentHashMap<>();
        GameParameterAssist.bk = new ConcurrentHashMap<>();
        GameParameterAssist.bl = new ConcurrentHashMap<>();
        GameParameterAssist.aN = new ConcurrentHashMap<>();
        GameParameterAssist.aP = new ConcurrentHashMap<>();
        GameParameterAssist.bs = new ConcurrentHashMap<>();
        GameParameterAssist.thousandFishGametypeMap = new ConcurrentHashMap<>();
        GameParameterAssist.goldenFishUserId = new ConcurrentHashMap<>();
        GameParameterAssist.likuiFishUserId = new ConcurrentHashMap<>();
        GameParameterAssist.goldSharkUserId = new ConcurrentHashMap<>();
        GameParameterAssist.bcbmUserId = new ConcurrentHashMap<>();
        GameParameterAssist.tgUserId = new ConcurrentHashMap<>();
        GameParameterAssist.lhdUserId = new ConcurrentHashMap<>();

        GameParameterAssist.bn = new ConcurrentHashMap<>();
        GameParameterAssist.bm = new ConcurrentHashMap<>();
        GameParameterAssist.bo = new ConcurrentHashMap<>();
        GameParameterAssist.bp = new ConcurrentHashMap<>();
        GameParameterAssist.bq = new ConcurrentHashMap<>();
        GameParameterAssist.aO = new ConcurrentHashMap<>();
        GameParameterAssist.aQ = new ConcurrentHashMap<>();
        GameParameterAssist.br = new ConcurrentHashMap<>();
        GameParameterAssist.thsandFishUserList = new ConcurrentHashMap<>();
        GameParameterAssist.likuiFishUserList = new ConcurrentHashMap<>();
        GameParameterAssist.goldenFishUserList = new ConcurrentHashMap<>();
        GameParameterAssist.tgUserList = new ConcurrentHashMap<>();
        GameParameterAssist.goldSharkUserList = new ConcurrentHashMap<>();
        GameParameterAssist.bcbmUserList = new ConcurrentHashMap<>();
        GameParameterAssist.lhdUserList = new ConcurrentHashMap<>();

        com.miracle9.game.util.UserParticipateRecord.initialize();
    }

    public Map<String, Object> stopCooperate(IoSession session) {
        Map result = new HashMap();
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        if (config.getGameStatus() == 0) {
            pubNotice();
        }
        config.setGameStatus(1);
        config.setOperationStatus(0);
        this.systemConfigServiceDao.updateWeihuStatus(config);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        GameStatus gs = new GameStatus();
        gs.statusIndex = config.getGameStatus();
        gs.cooperateMode = config.getOperationStatus();
        gs.cooperateStartDate = "——————";
        gs.cooperateEndDate = "——————";
        for (Map.Entry entry : GameParameterAssist.be.entrySet()) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity((IoSession) entry.getValue(), "syncGameStatus", new Object[]{gs}));
        }
        return result;
    }

    public Map<String, Object> startCooperate(String endDate, IoSession session) {
        Map result = new HashMap();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String startDate = sdf.format(new Date());
        long endTime = 0L;
        try {
            endTime = sdf.parse(endDate).getTime();
        } catch (ParseException localParseException) {
        }
        if (endTime < System.currentTimeMillis()) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "setTimeError"));
            return result;
        }
        this.systemConfigServiceDao.updateOperation_3(1, startDate, endTime);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        GameStatus gs = new GameStatus();
        if (config.getGameStatus() == 0) {
            if (config.getWeihuTime() == -1) {
                gs.statusIndex = 0;
            } else {
                gs.statusIndex = 2;
                gs.time = config.getWeihuTime();
                gs.content = config.getContent();
            }
        } else {
            gs.statusIndex = 1;
        }
        gs.cooperateMode = config.getOperationStatus();
        gs.cooperateStartDate = "——————";
        gs.cooperateEndDate = "——————";
        if (config.getOperationStatus() == 1) {
            gs.cooperateStartDate = config.getOperationDate();
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(config.getOperationStopDate());
            gs.cooperateEndDate = sdf.format(c.getTime());
        }
        for (Map.Entry entry : GameParameterAssist.be.entrySet()) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new StorageMethodEntity((IoSession) entry.getValue(), "syncGameStatus", new Object[]{gs}));
        }
        return result;
    }

    public boolean checkSwitchWork(IoSession session) {
        return this.busineInfoServiceDao.q_CreateSqlInt("select count(*) from BusineInfo where shiftWorkStatus = 0 and waiter=1", new Object[0]) > 0;
    }

    public void updateWeihuStatus(SystemConfig config) {
        this.systemConfigServiceDao.updateWeihuStatus(config);
    }

    public Map<String, Object> updateBaodanPwd(String newPwd, IoSession session) {
        Map result = new HashMap();
        String md5Pwd = DigestUtils.md5Hex(newPwd);
        this.systemConfigServiceDao.updateBaodanPwd(md5Pwd);
        getSystemConfig().setBaodanPwd(md5Pwd);

        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog(admin.getUsername(), "修改保单箱控制系统密码", 2, admin.getType(), "Change the password of printer");
        this.adminLogServiceDao.addAdminLog(adminLog);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        return result;
    }

    public int baodanCount(int baodanType, IoSession session) {
        int nCount = 0;
        if (GameParameterAssist.aM.get(Integer.valueOf(baodanType)) == null) {
            GameParameterAssist.aM.put(Integer.valueOf(baodanType), Integer.valueOf(nCount));
        }
        if (GameParameterAssist.aM.containsKey(Integer.valueOf(baodanType))) {
            nCount = ((Integer) GameParameterAssist.aM.get(Integer.valueOf(baodanType))).intValue();
        }
        return nCount;
    }

    public Map<String, Object> baodanCountNew(int baodanType, IoSession session) {
        Map result = new HashMap();
        int nCount = 0;
        if (GameParameterAssist.aM.get(Integer.valueOf(baodanType)) == null) {
            GameParameterAssist.aM.put(Integer.valueOf(baodanType), Integer.valueOf(nCount));
        }
        if (GameParameterAssist.aM.containsKey(Integer.valueOf(baodanType))) {
            nCount = GameParameterAssist.aM.get(Integer.valueOf(baodanType)).intValue();
            result.put("count", nCount);
            result.put("baodanType", baodanType);
        }
        return result;
    }

}
